"""
员工管理模块接口对象层
"""
import requests


class IhrmEmpCURD(object):
    #添加
    @classmethod
    def add_emp(cls,header,json_data):
        url = "http://ihrm-java.itheima.net/api/sys/user"
        resp = requests.post(url=url, headers=header, json=json_data)

        return resp
    #查询
    @classmethod
    def query_emp(cls,emp_id,header):
        url_query = "http://ihrm-java.itheima.net/api/sys/user/"+emp_id
        resp = requests.get(url=url_query, headers=header)

        return resp

    #修改
    @classmethod
    def modify_emp(cls,emp_id,header,modify_data):
        url= "http://ihrm-java.itheima.net/api/sys/user/"+emp_id
        resp = requests.post(url=url, headers=header, json=modify_data)

        return resp

    #删除
    @classmethod
    def del_emp(cls,emp_id, header):
        url = "http://ihrm-java.itheima.net/api/sys/user/"+emp_id
        resp = requests.delete(url=url, headers=header)

        return resp

if __name__ == '__main__':
    header={"Content-Type":"application/json",
                "Authorization":"Bearer c1159ac9-d280-437b-a9b0-6961c744e674"}
    data_add={
"username": "业务猪001",
    "mobile": "13978687694",
    "workNumber": "9527"
}
    resp=IhrmEmpCURD.add_emp(header,data_add)
    print("添加：",resp.json())

    emp_id="1063705989926227968"
    resp=IhrmEmpCURD.query_emp(emp_id,header)
    print("查询：", resp.json())

    data= {"username": "猪猪皇子"}
    resp=IhrmEmpCURD.modify_emp(emp_id,header,data)
    print("修改：", resp.json())

    resp=IhrmEmpCURD.del_emp(emp_id,header)
    print("删除：", resp.json())

